﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 软件类别 数据类
    /// </summary>
    public class SoftwareCatalog
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public SoftwareCatalog()
        {
        }
        /// <summary>
        /// 根据公司编码获取软件类别
        /// <creator>wangl</creator>
        /// <date>2013-09-10</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public DataSet GetListByFEntityNo(string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT  FSoftwareCatalogID , ");
            strSql.Append(" FPreSoftwareCatalogID ,");
            strSql.Append(" FSoftwareCatalogName ,");
            strSql.Append(" FEntityNo");
            strSql.Append(" FROM t_SoftwareCatalog ");
            strSql.Append(" WHERE FEntityNo = @FEntityNo");

            SqlParameter[] parameters = { 
                        new SqlParameter("@FEntityNo",SqlDbType.NVarChar,12)
                                        };
            parameters[0].Value = entityNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-09-10</date>
        /// </summary>
        /// <param name="softwareCatalogID">软件种类编号</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns></returns>
        public Model.SoftwareCatalog GetModel(decimal softwareCatalogID, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT TOP 1 ");
            strSql.Append(" FSoftwareCatalogID , ");
            strSql.Append(" FPreSoftwareCatalogID , ");
            strSql.Append(" FSoftwareCatalogName , ");
            strSql.Append(" FEntityNo ");
            strSql.Append(" FROM    t_SoftwareCatalog ");
            strSql.Append(" WHERE   FSoftwareCatalogID = @FSoftwareCatalogID ");
            strSql.Append(" AND FEntityNo = @FEntityNo ");

            SqlParameter[] parameters = {
					new SqlParameter("@FSoftwareCatalogID", SqlDbType.Decimal),
                    new SqlParameter("@FEntityNo",SqlDbType.NVarChar,12)
			};
            parameters[0].Value = softwareCatalogID;
            parameters[1].Value = entityNo;

            Model.SoftwareCatalog model = new Model.SoftwareCatalog();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>wangl</creator>
        /// <date>2013-09-10</date>
        /// </summary>
        public Model.SoftwareCatalog DataRowToModel(DataRow row)
        {
            Model.SoftwareCatalog model = new Model.SoftwareCatalog();
            if (row != null)
            {
                if (row["FSoftwareCatalogID"] != null && row["FSoftwareCatalogID"].ToString() != "")
                {
                    model.FSoftwareCatalogID = decimal.Parse(row["FSoftwareCatalogID"].ToString());
                }
                if (row["FPreSoftwareCatalogID"] != null && row["FPreSoftwareCatalogID"].ToString() != "")
                {
                    model.FPreSoftwareCatalogID = decimal.Parse(row["FPreSoftwareCatalogID"].ToString());
                }
                if (row["FSoftwareCatalogName"] != null)
                {
                    model.FSoftwareCatalogName = row["FSoftwareCatalogName"].ToString();
                }
                if (row["FEntityNo"] != null)
                {
                    model.FEntityNo = row["FEntityNo"].ToString();
                }
            }
            return model;
        }
    }
}
